package com.example.novel.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.novel.domain.Evaluate;
import com.example.novel.domain.Result;
import com.example.novel.service.EvaluateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

//评价的增，删，查
//评价管理
@Controller
@RequestMapping("/evaluate")
public class EvaluateController {
    @Resource
    private EvaluateService evaluateService;

    @ResponseBody
    @RequestMapping("/getEvaluate/{id}")//获取评价
    public Result getEvaluate(@PathVariable Integer id) {
        return evaluateService.getEvaluate(id);
    }

    @ResponseBody
    @RequestMapping("/deleteEvaluate/{id}")//删除评价
    public Result deleteEvaluate(@PathVariable Integer id) {
        LambdaQueryWrapper<Evaluate> wrapper = new LambdaQueryWrapper<Evaluate>()
                .eq(Evaluate::getEvaluateId, id);
        evaluateService.remove(wrapper);
        return new Result();
    }

    @ResponseBody
    @RequestMapping("/addEvaluate")
    public Result addEvaluate(@RequestBody Evaluate evaluate) {
        Evaluate evaluate1 = new Evaluate();
        evaluate1.setBookId(evaluate.getBookId());
        evaluate1.setUserId(evaluate.getUserId());
        evaluate1.setComment(evaluate.getComment());
        evaluate1.setSatisfy(evaluate.getSatisfy());
        evaluate1.setCreatedAt(evaluate.getCreatedAt());
        evaluate1.setUpdatedAt(evaluate.getUpdatedAt());
        evaluateService.save(evaluate1);
        return new Result();
    }
    @ResponseBody
    @RequestMapping("/getEvaluateById/{userId}")//获取用户评价
    public Result getEvaluateById(@PathVariable String userId) {
        System.out.println(userId);
        return evaluateService.getEvaluateById(userId);
    }
}
